﻿using EMall.ProductService.Products;
using EMall.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace EMall.ProductService.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ProductController : ControllerBase, IProductAppService
    {
        private readonly IProductAppService _productAppService;
        public ProductController(IProductAppService productAppService)
        {
            _productAppService = productAppService;
        }
        [HttpPost]
        public async Task CreateAsync(CreateProductDto input)
        {
            await _productAppService.CreateAsync(input);
        }
        [HttpPut]
        public async Task UpdateAsync(UpdateProductDto input)
        {
            await _productAppService.UpdateAsync(input);
        }
        [HttpDelete]
        public async Task DeleteAsync(DeleteProductDto input)
        {
            await _productAppService.DeleteAsync(input);
        }
        [HttpGet]
        public async Task<ProductDto> GetAsync(int id)
        {
            return await _productAppService.GetAsync(id);
        }
        [HttpGet]
        public async Task<IPagedList<ProductListDto>> GetPagedListAsync([FromQuery] GetProductListPagingAndSortingQueryDto input)
        {
            return await _productAppService.GetPagedListAsync(input);
        }

    }
}
